package org.springframework.prospring.ticket.service.impl;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.prospring.ticket.dao.SportDAO;
import org.springframework.prospring.ticket.domain.sport.Sport;
import org.springframework.prospring.ticket.service.SportManager;

import java.util.Collection;

public class SportManagerImpl implements SportManager {
    private static Log logger = LogFactory.getLog(SportManagerImpl.class);
    private SportDAO dao;

    public SportManagerImpl() {
        super();
        if (logger.isDebugEnabled()) {
            logger.debug("in SportManagerImpl Constructor");
        }
    }

    public void setSportDAO(SportDAO dao) {
        if (logger.isDebugEnabled()) {
            logger.debug("setting SportDAO: " + dao);
        }

        this.dao = dao;
    }


    public Collection<Sport> findAllSports(){
        if (logger.isDebugEnabled()) {
            logger.debug("finding all Sports ");
        }
        Collection<Sport> sports = dao.findAllSports();

        if (sports == null) {
            logger.warn("Not found any Sports in database.");
        }

        return sports;
    }


    public Sport saveSport(Sport sport) throws Exception {
        if (logger.isDebugEnabled()) {
            logger.debug("saving Sport: " + sport);
        }

        dao.saveSport(sport);

        return sport;
    }

    public void removeSport(Long sportId) {
        dao.removeSport(sportId);
    }


}
